<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>车辆维护信息</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../../layui-v2.6.8/layui/css/layui.css">
    <!--    <link rel="stylesheet" href="../../layui-v2.6.8/layui/layui.js" media="all">-->
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>

<!--<blockquote class="layui-elem-quote layui-text">-->
<!--    鉴于小伙伴的普遍反馈，先温馨提醒两个常见“问题”：1. <a href="/doc/base/faq.html#form" target="_blank">为什么select/checkbox/radio没显示？</a> 2. <a href="/doc/modules/form.html#render" target="_blank">动态添加的表单元素如何更新？</a>-->
<!--</blockquote>-->

<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>车辆维护信息修改页面</legend>
</fieldset>
<form class="layui-form" action="">
    <div class="layui-form-item">
        <label class="layui-form-label">车辆维护编号</label>
        <div class="layui-input-block">
            <select id="mid" name="vid" lay-verify="required" lay-filter="s">
                <option value="">请选择</option>
            </select>
            <!--      <a href="updateDirver.html" class="layui-btn layui-btn-danger layui-btn-xs">修改司机信息</a>-->
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">操作人员</label>
        <div class="layui-input-block">
            <select id="eidm" name="eid" lay-verify="required" lay-filter="a">
                <option value="">请选择</option>
            </select>
            <!--      <a href="addDirver.html" class="layui-btn layui-btn-danger layui-btn-xs">添加司机信息</a>-->
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">保养费用</label>
            <div class="layui-input-inline">
                <input type="text" id="maintain" required lay-verify="required" placeholder="请输入保养费用" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">修理费用</label>
            <div class="layui-input-inline">
                <input type="text" id="repair" required lay-verify="required" placeholder="请输入修理费用" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">维护时间</label>
            <div class="layui-input-inline">
                <input type="text" id="mtime" required lay-verify="required" placeholder="请输入时间：“XXXX-XX-XX”" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">维护状态</label>
            <div class="layui-input-block">
                <select id="mstatus" lay-verify="required">
                    <option value=""></option>
                    <option value="需要维护">需要维护</option>
                    <option value="维护中">维护中</option>
                    <option value="维护完成">维护完成</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">维护地点</label>
            <div class="layui-input-inline">
                <input type="text" id="maddress" required lay-verify="required" placeholder="请输入维护地点" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">维护费用</label>
            <div class="layui-input-inline">
                <input type="text" id="mcost" required lay-verify="required" placeholder="请输入维护费用" autocomplete="off" class="layui-input">
            </div>
        </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" onclick="update()">修改</button>
        </div>
    </div>
</div>
</form>
<script src="../../../layui-v2.6.8/layui/layui.js"></script>
<script>
    layui.use(['form','layer'],function() {
        var form = layui.form;
        var $ = layui.$;
        // var layer = layui.layer;
        form.on('select(s)', function (data) {
            $.ajax({
                type: 'get',
                url: 'http://localhost:8080/byMid',
                dataType: 'json',
                async: false,
                cache: false,
                success: function (data) {
                    $.each(data.data, function (index, item) {
                        $('#mid').append(new Option(item.mid))

                    });
                    layui.form.render("select");
                }
            })
        });
    });
    layui.use(['form','layer'],function() {
        var form = layui.form;
        var $ = layui.$;
        // var layer = layui.layer;
        form.on('select(a)', function (data) {
            $.ajax({
                type: 'get',
                url: 'http://localhost:8080/searchByepost',
                dataType: 'json',
                async: false,
                cache: false,
                success: function (data) {
                    $.each(data.data, function (index, item) {
                        $('#eidm').append(new Option(item.ename, item.eid))

                    });
                    layui.form.render("select");
                }
            })
        });
    });
    function update() {
        var $ =layui.$;
        var maintain =$("#maintain").val();
        var repair =$("#repair").val();
        var eidm =$("#eidm").val();
        var mtime =$("#mtime").val();
        var mstatus =$("#mstatus").val();
        var maddress =$("#maddress").val();
        var mcost =$("#mcost").val()
        console.log(maintain);
        var data={

            "maintain":maintain,
            "eidm":eidm,
            "repair":repair,
            "mtime":mtime,
            "mstatus":mstatus,
            "maddress":maddress,
            "mcost":mcost,

        }
        var layer = layui.layer;
        var url ="http://localhost:8080/updateMain";
        $.ajax({
            url:url,
            type:"get",
            dataType:"json",
            async:true,
            // cache:false,
            data:data,
            success: function(data){
                console.log(data)
                if (data.code == 0) {

                    layer.msg("修改成功", {icon: 6,time:1800},function (){
                        // location.href = '../car/addCar.html';
                    });
                    window.location.href = 'MainIndex.html';
                } else {
                    layer.msg("修改失败", {icon: 5});
                }
                return false;
            }
        });
    }
</script>